use tokio::sync::broadcast;



pub struct Messager<T> {
    tx: broadcast::Sender<T>,
    _rx: broadcast::Receiver<T>,
}

impl <T: Default + Clone> Messager<T> {

    pub fn new() -> Self {
        let (tx, rx) = broadcast::channel(64);
        Self { tx, _rx: rx }
    }

    pub fn receiver_count(&self) -> usize {
        self.tx.receiver_count()
    }

    pub fn notify(&self, msg: T) {
        _ = self.tx.send(msg);
    }

    pub fn subscribe(&self) -> broadcast::Receiver<T> {
        self.tx.subscribe()
    }
}


